﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;

namespace LabChecker.Models
{
    public static class FileSystemService
    {
        public static string CreateTempDirectory()
        {
            string dirName = Path.Combine(Path.GetTempPath(), "labChecker", Guid.NewGuid().ToString());
            Directory.CreateDirectory(dirName);
            return dirName;
        }

        public static void CreateFileFromText(string fileName, string text)
        {
            StreamWriter sw = new StreamWriter(fileName);
            sw.Write(text);
            sw.Close();
        }

        public static string GetFileContents(string fileName)
        {
            //FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
            StreamReader sr = new StreamReader(fileName);
            string contents = sr.ReadToEnd();
            sr.Close();
            return contents;
        }

        public static void DeleteDirectory(string dirName)
        {
            if (Directory.Exists(dirName))
            {
                try
                {
                    Directory.Delete(dirName, true);
                }
                catch { }
            }
        }
    }
}